package com.atguigu.demo.customer.service.impl;

import com.atguigu.demo.customer.bean.Customer;
import com.atguigu.demo.customer.mapper.CustomerMapper;
import com.atguigu.demo.customer.service.CustomerService;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service   // 组件标识
@DS("demo")
public class CustomerServiceImpl extends ServiceImpl<CustomerMapper,Customer> implements CustomerService {

    @Autowired
    CustomerMapper customerMapper;


    @Override
    public void saveCustomer(Customer customer) {
       // customerMapper.insertCustomer(customer);
        customerMapper.insert(customer);

    //    System.out.println("save customer = " + customer);
    }

    @Override
    public Customer getCustomerById(Integer id) {
   //     Customer customer = customerMapper.selectCustomerById(id);
        Customer customer = customerMapper.selectById(id);
        return customer;
    }

    public List<Customer> getCustomerList(Customer customer){
    //    List<Customer> customers = customerMapper.selectCustomer(customer);
        QueryWrapper<Customer> queryWrapper = new QueryWrapper<Customer>().like("name", customer.getName());
        List<Customer> customerList = customerMapper.selectList(queryWrapper);

        return customerList;
    }


}
